package mististore;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.*;
import net.tanesha.recaptcha.ReCaptchaImpl;
import net.tanesha.recaptcha.ReCaptchaResponse;

@SuppressWarnings("serial")
public class ServletCaptcha extends HttpServlet
{
	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException
	{
		resp.setContentType("text/html;charset=UTF-8");
	    PrintWriter out=resp.getWriter();
		
		String remoteAddr=req.getRemoteAddr();
		ReCaptchaImpl reCaptcha=new ReCaptchaImpl();
		reCaptcha.setPrivateKey("6LehxdMSAAAAABO1oYVTno5kB0yBkm7thx8QTOBq");
		String challenge=req.getParameter("recaptcha_challenge_field");
		String uresponse=req.getParameter("recaptcha_response_field");
		ReCaptchaResponse reCaptchaResponse=reCaptcha.checkAnswer(remoteAddr,challenge,uresponse);
		if(reCaptchaResponse.isValid())
		{
			out.println("OK");
		}
		else
		{
			out.print("FAIL");
		}
	}
}
